package com.hzp.lolnews.ui.news.view;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.hzp.lolnews.bean.HomeRow;

import java.util.List;

/**
 * Created by Administrator on 2016/10/19 0019.
 */
public class HomeHeadAdapter extends PagerAdapter {

    private List<HomeRow> mList;

    public HomeHeadAdapter(){

    }

    public void setData(List<HomeRow> image) {
        this.mList = image;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return mList != null ? Integer.MAX_VALUE : 0;


    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        SimpleDraweeView simpleDraweeView = new SimpleDraweeView(container.getContext());
        simpleDraweeView.setScaleType(ImageView.ScaleType.FIT_XY);
        simpleDraweeView.setImageURI(mList.get(position % mList.size()).getImg());
        container.addView(simpleDraweeView);
        return simpleDraweeView;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((SimpleDraweeView)object);
    }
}
